<?php
require_once 'header.php';

// 获取所有产品
$products = getAllProducts();
?>

<div class="jumbotron bg-dark text-white">
    <div class="container">
        <h1 class="display-4">欢迎来到影院电商系统</h1>
        <p class="lead">在这里您可以购买最新的电影票、套餐和会员卡</p>
        <?php if (!isLoggedIn()): ?>
        <hr class="my-4">
        <p>立即登录或注册，开始您的购物之旅！</p>
        <a class="btn btn-primary btn-lg mr-2" href="login.php" role="button">登录</a>
        <a class="btn btn-outline-light btn-lg" href="register.php" role="button">注册</a>
        <?php endif; ?>
    </div>
</div>

<div class="container">
    <h2 class="mb-4">热门电影票</h2>
    
    <div class="row">
        <?php foreach($products as $product): ?>
        <div class="col-md-4 col-sm-6 mb-4">
            <div class="card product-card">
                <img src="<?php echo !empty($product['image']) ? $product['image'] : 'https://via.placeholder.com/300x200?text=电影票'; ?>" class="card-img-top product-image" alt="<?php echo $product['name']; ?>">
                <div class="card-body">
                    <h5 class="card-title"><?php echo $product['name']; ?></h5>
                    <p class="card-text"><?php echo mb_substr($product['description'], 0, 60, 'UTF-8') . (mb_strlen($product['description'], 'UTF-8') > 60 ? '...' : ''); ?></p>
                    <div class="d-flex justify-content-between align-items-center">
                        <span class="text-danger font-weight-bold">¥<?php echo number_format($product['price'], 2); ?></span>
                        <a href="product.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-outline-primary">查看详情</a>
                    </div>
                </div>
                <div class="card-footer bg-white">
                    <form action="add_to_cart.php" method="post">
                        <input type="hidden" name="product_id" value="<?php echo $product['id']; ?>">
                        <button type="submit" class="btn btn-block btn-primary">
                            <i class="fas fa-shopping-cart mr-2"></i>加入购物车
                        </button>
                    </form>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
    </div>
    
    <div class="row my-5">
        <div class="col-md-4">
            <div class="card mb-3">
                <div class="card-body text-center">
                    <i class="fas fa-ticket-alt fa-3x text-primary mb-3"></i>
                    <h5>便捷购票</h5>
                    <p class="text-muted">随时随地，在线选座，快捷支付</p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card mb-3">
                <div class="card-body text-center">
                    <i class="fas fa-percent fa-3x text-primary mb-3"></i>
                    <h5>会员优惠</h5>
                    <p class="text-muted">会员专享价格，积分兑换好礼</p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card mb-3">
                <div class="card-body text-center">
                    <i class="fas fa-film fa-3x text-primary mb-3"></i>
                    <h5>最新影片</h5>
                    <p class="text-muted">第一时间获取最新影片信息</p>
                </div>
            </div>
        </div>
    </div>
</div>

<?php require_once 'footer.php'; ?> 